import wsgiref.handlers
import appcons
import appdb

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

class ReportError(webapp.RequestHandler):
  def get(self):
    if not self.request.get("url"): return
    error = appdb.GetErrorReport(self.request.get("url").encode("utf-8"))
    if error is None:
      error = appdb.ErrorReport(key_name = appdb.GenURLKeyName("ErrorReport",
                                                               self.request.get("url").encode("utf-8")),
                                url = self.request.get("url"))
    error.count += 1
    error.put()
    values = {
              "appname": appcons.AppName(),
              "summary": appcons.Info(),
              "content": appcons.ReportError(error.count),
              }

    self.response.out.write(template.render("./pages/basecontent.html", values))

def main():
  application = webapp.WSGIApplication([("/userreporterror", ReportError),
                                        ],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
